package com.lcy.eb.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lcy.eb.mapper.EbNewsMapper;
import com.lcy.eb.mapper.EbProductMapper;
import com.lcy.eb.model.EbNews;
import com.lcy.eb.model.EbProduct;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class IndexService {
    @Resource
    private EbProductMapper ebProductMapper;
    @Resource
    private EbNewsMapper ebNewsMapper;
    public Map<String, Page> index(int page,int pageSize){
        System.out.println("进入到service");
        Page init=new Page(page,pageSize);
        Page productPage=ebProductMapper.selectPage(init,null);
        System.out.println("查询商品为"+productPage);
        Page newinit=new Page(1,8);
        Page newsPage=ebNewsMapper.selectPage(newinit,new QueryWrapper<EbNews>()
                .orderByDesc("en_create_time"));
        Map<String,Page>result=new HashMap<>();
        result.put("news",newsPage);
        result.put("product",productPage);
        return result;
    }


    public Map<String, Page> category(int epId,int page,int pageSize){
//        System.out.println("进入到service");
        Page init=new Page(page,pageSize);
        Page productPage=ebProductMapper.selectPage(init,new QueryWrapper<EbProduct>().eq("epc_child_id",epId));
//        System.out.println("查询商品为"+productPage);
        Map<String,Page>result=new HashMap<>();
        result.put("categoryProductPage",productPage);
        return result;
    }
}
